# -*- coding: utf-8 -*-
"""
Created on Thu May 23 17:27:36 2013

@author: Maxim
"""
import aircraft
from numpy import zeros

def rect_inertia(m,a,b,l):
    Ixx = 1.0/12.0*m*(a*a+b*b)
    Iyy = 1.0/12.0*m*(l*l+b*b)
    Izz = 1.0/12.0*m*(l*l+a*a)
    return Ixx,Iyy,Izz

def circ_inertia(m,r,l):
    Ixx = m*r*r/2.0
    Iyy = 1.0/12.0*m*(3*r*r+l*l)
    Izz = Iyy
    return Ixx,Iyy,Izz

def calculate_part_inertia():
    ac = aircraft.load('V0510')
    name = ['main wing','hStab','vStab','fuselage']
    Ixx, Iyy, Izz = zeros(len(name)),zeros(len(name)),zeros(len(name))
    
    i = 0
    m = 56.30
    a = ac.wing.MAC
    b = ac.wing.thicknessRatio*a
    l = ac.wing.span
    Ixx[i],Iyy[i],Izz[i] = rect_inertia(m,a,b,l)
    
    i = 1
    m = 10.40
    a = ac.hStab.MAC
    b = ac.hStab.thicknessRatio*a
    l = ac.hStab.span
    Ixx[i],Iyy[i],Izz[i] = rect_inertia(m,a,b,l)
    
    i = 2
    #m = ac.mass.airframe.get_item_mass_by_name('vStab')
    m = 3.8
    a = ac.vStab.MAC
    b = ac.vStab.span
    l = ac.vStab.thicknessRatio*a
    Ixx[i],Iyy[i],Izz[i] = rect_inertia(m,a,b,l)
    
    i = 3
    m = 66.20+16.80-1.9+66.9
    r = ac.fuselage.diameter / 2.0
    l = ac.fuselage.length
    Ixx[i],Iyy[i],Izz[i] = circ_inertia(m,r,l)
    
    print 'unit: kg*m^2'
    out = '{0:15}|{1:^12}|{2:^12}|{3:^12}|'.format('name','Ixx','Iyy','Izz')
    print out + '\n' + '='*len(out)
    for i,n in enumerate(name):
        print '{0:15} {1:12.4f} {2:12.4f} {3:12.4f}'.format(n, Ixx[i],Iyy[i],Izz[i])



if __name__=="__main__":
    calculate_part_inertia()